import request from '@/utils/request'
import store from '@/store'
//const ascriptionId = store.state.userInfo.ascriptionId;

// 页面内容 左侧树 课程分类 树列表数据
export function getPage(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize
  }
  return request({
    url: '/getCurriculumPage',
    method: 'post',
    data: data
  })
}

// 数据列表
export function listData(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
    keywords: queryParams.keywords,
    speakerId: queryParams.speakerId,
    category: queryParams.category, //课程类型
    curriculumType: queryParams.curriculumType, //课程分类
  }
  return request({
    url: '/getCurriculumList',
    method: 'post',
    data: data
  })
}

// 新增
export function addData(val) {
  const data = {
    projectContent: {
      ascriptionId: store.state.userInfo.ascriptionId,
      typeId: val.typeId, //课程类型 id
      typeVal: val.typeVal, //课程类型
      categoryId: val.classificationId, //课程分类 id
      categoryVal: val.classification, //课程分类
      title: val.title, //课程名称
      introduction: val.introduce, //课程介绍
      thePic: val.thePic, //资源配图
      resourceList: val.resourceList, //资源列表
      speakerId: val.speakerId, //主讲人 id
      speaker: val.speaker, //主讲人
      classHours: val.classHours, //资源学时
      credit: val.credit, //资源学分
      theYear: val.curriculumYear, //课程年份
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
      startTime: val.startTime, //课程开始时间
      endTime: val.endTime, //课程结束时间
    }
  }
  return request({
    url: '/addCurriculum',
    method: 'post',
    data: data
  })
}

// 获取单条数据
export function getData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/getCurriculumData',
    method: 'post',
    data: data
  })
}

// 修改
export function updateData(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      typeId: val.typeId, //课程类型 id
      typeVal: val.typeVal, //课程类型
      categoryId: val.classificationId, //课程分类 id
      categoryVal: val.classification, //课程分类
      title: val.title, //课程名称
      introduction: val.introduction, //课程介绍
      thePic: val.thePic, //资源配图
      resourceList: val.resourceList, //资源列表
      speakerId: val.speakerId, //主讲人 id
      speaker: val.speaker, //主讲人
      classHours: val.classHours, //资源学时
      credit: val.credit, //资源学分
      theYear: val.theYear, //课程年份
      publisherId: val.publisherId, //发布人id
      publisher: val.publisher, //发布人
      startTime: val.startTime, //课程开始时间
      endTime: val.endTime, //课程结束时间
    }
  }
  return request({
    url: '/updateCurriculum',
    method: 'post',
    data: data
  })
}

// 删除
export function delData(theid) {
  const data = {
    theid
  }
  return request({
    url: '/delCurriculum',
    method: 'post',
    data: data
  })
}

// 批量删除   idListStr id列表  逗号隔开
export function delMultiData(idListStr) {
  const data = {
    idListStr
  }
  return request({
    url: '/delMultipleCurriculum',
    method: 'post',
    data: data
  })
}

// 下拉框
export function getSelect() {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
  }
  return request({
    url: '/getCurriculumComboBox',
    method: 'post',
    data: data
  })
}

// 培训讲师下拉
export function teacherList(queryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: queryParams.currentPage,
    pagesize: queryParams.pagesize,
  }
  return request({
    url: '/getLecturerList',
    method: 'post',
    data: data
  })
}

// 修改启用状态  enable 启用状态  0-未启用 1-已启用
export function getEnable(theid, enable) {
  const data = {
    projectContent: {
      theid,
      enable
    }
  }
  return request({
    url: '/changeEnableCurriculum',
    method: 'post',
    data: data
  })
}

// 课程分类
export function getkinds(platform, sid) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    platform,
    sid
  }
  return request({
    url: '/getListAllDictionary',
    method: 'post',
    data: data
  })
}

// 设置弹框 选择分类
export function getclass(coursequeryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: coursequeryParams.currentPage,
    pagesize: coursequeryParams.pagesize,
    theType: coursequeryParams.theType, //资源库类型 1-公共资料库 2-行业资料库 3-企业资料库
  }
  return request({
    url: '/getResourcePage',
    method: 'post',
    data: data
  })
}

// 设置弹框 列表
export function getclassList(coursequeryParams) {
  const data = {
    ascriptionId: store.state.userInfo.ascriptionId,
    currentPage: coursequeryParams.currentPage,
    pagesize: coursequeryParams.pagesize,
    theType: coursequeryParams.theType,
    resourceType: coursequeryParams.resourceType
  }
  return request({
    url: '/getResourceList',
    method: 'post',
    data: data
  })
}

// 设置课程
export function setCourse(val) {
  const data = {
    projectContent: {
      theid: val.theid, //id
      resourceList: val.resourceList, //资源id列表
    }
  }
  return request({
    url: '/setCoursesCurriculum',
    method: 'post',
    data: data
  })
}

// 删除
export function delCourseResource(theid, resourceId) {
  const data = {
    theid,   //课程 id
    resourceId   //课程资源 id
  }
  return request({
    url: '/delCoursesResource',
    method: 'post',
    data: data
  })
}